package cn.wolfcode.wolf2world.web.advice;

import cn.wolfcode.wolf2world.exception.LogicException;
import cn.wolfcode.wolf2world.vo.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 杨兴健
 * @Date 2020/8/8 19:33
 */
@RestControllerAdvice
public class MyExceptionHandler {

    /**
     * 处理自定义的逻辑异常
     * @param ex 捕获的异常
     * @return
     */
    @ExceptionHandler(LogicException.class)
    public Object logicException(Exception ex) {
        ex.printStackTrace();
        return JsonResult.error(JsonResult.CODE_ERROR_PARAM, ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Object exception(Exception e) {
        e.printStackTrace();
        return JsonResult.error(500,e.getMessage());
    }
}
